#include <iostream>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;
const int N = 2e3 + 10;
int dist[N];
int st[N];
vector<pair<int,int>> edges[N];
int cnt[N];
int n,m;

bool spfa()
{
    memset(dist,0x3f,sizeof dist);
    memset(cnt,0,sizeof cnt);
    memset(st,0,sizeof st);

    dist[1] = 0;
    queue<int> q;
    q.push(1);
    while(q.size())
    {
        int u = q.front();
        q.pop();
        st[u] = false;
        for(auto& e : edges[u])
        {
            int v = e.first,w = e.second;
            if(dist[u] + w < dist[v])
            {
                dist[v] = dist[u] + w;
                cnt[v] = cnt[u] + 1;
                if(cnt[v] >= n)return true;
                if(st[v] == false)
                {
                    q.push(v);
                    st[v]=true;
                }
            }
        }
    }
    return false;
}

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        cin >> n >> m;
        for(int i = 1; i <= n; i++)
        {
            edges[i].clear();
        }
        for(int i = 1; i <= m; i++)
        {
            int u,v,w;
            cin >> u >> v >> w;
            edges[u].push_back({v,w});
            if(w >=0)
            edges[v].push_back({u,w});
        }
        if(spfa())cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}